<?php
/**
 * db select to connect
 *@date 2012-1-1
 *@author zhouyt
 *@version 1.0
 *@return db
 */

class Page {
	
	/**
	 * single instance
	 *@var Zyt_Common
	 */
	protected static $_instance = null;

	/**
	 * makes "new"
	 *@return void
	 */
	protected function __construct()
	{}

	/**
	 * makes "clone"
	 *@return void
	 */
	protected function __clone()
	{}

	/**
	 * return an instance of Zyt_Common
	 *@return an instance
	 */
	public static function getInstance()
	{
		if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
	}

	/**
	 *@return page info
	 */
	public function getPaging($arr)
	{
		if (isset($arr['size']) && intval($arr['size']) > 0)
		{
			$arr['size'] = intval($arr['size']);
		}
		else
		{
			$arr['size'] = 100;
		}

		/* 第几页 */
		$arr['page'] = (empty($arr['page']) || intval($arr['page']) <= 0) ? 1 : intval($arr['page']);

		/* page 总数 */
		$arr['pages'] = (!empty($arr['records']) && $arr['records'] > 0) ? ceil($arr['records'] / $arr['size']) : 1;

		/* 边界处理 */
		if ($arr['page'] > $arr['pages'])
		{
			$arr['page'] = $arr['pages'];
		}

		$arr['start'] = ($arr['page'] - 1) * $arr['size'];
	
		return $arr;
	}

	public function getPagingToolbar()
	{
	
	}
}

?>